package com.livgo.controller;

import com.livgo.dao.po.Result;
import com.livgo.service.SecretKeyService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/secretKey")
public class SecretKeyController {

    @Autowired
    private SecretKeyService secretKeyService;

    @Value("${SuperKey}")
    private String superKey;

    @GetMapping("/key")
    public Result<String> key(@Param("key") String pwd) {

        if (pwd == null || pwd.isEmpty()) {
            return Result.error("密码不能为空");
        }

        if (!pwd.equals(superKey)) {
            return Result.error( "密码错误");
        }

        String key = secretKeyService.genKey();

        return Result.success(key);

    }

}
